
/***************滑动到顶部*****************/
$(".zc-toolbar-tabbar > .toTop").click(function(){
	
	document.documentElement.scrollTop = 0;
	
});

/*设置上部导航的点击效果*/
$("li:has(.zc-hd)").css({"padding-right":22});

	$("li:has(.zc-hd)").mouseover(function(){
		
		$(this).css({"background":"white"});
		
		$(this).children("div").stop().slideDown();
		
	}).mouseout(function(){
		
		$(this).css({"background":""});
		$(this).children("div").stop().slideUp();
		
});




/**************************登录检测*************************/
var uSpan = document.getElementById("zc-login");
var aSpan = document.getElementById("zc-register");

/******************放大镜的滑动**********************/
var iDiv = document.getElementById("zs-big-pic");
var gDiv = document.getElementById("glass");
var bDiv = document.getElementById("bigDiv");
var bIm = document.getElementById("bImg");
var oImg = document.getElementById("orImg");

var gW = parseInt(getStyle(gDiv,"width"));
var gH = parseInt(getStyle(gDiv,"height"));


iDiv.onmousemove = function(event){
	
	event = event || window.event;
	
	var x = event.clientX - iDiv.offsetLeft;
	var y = event.clientY - iDiv.offsetTop;
	
	x -= gW/2;
	y -= gH/2;
	
	if(x<0){
		x=0
	}
	if(y < 0){
		
		y = 0
	}
	
	if(x>iDiv.offsetWidth - gDiv.offsetWidth){
		
		x = iDiv.offsetWidth - gDiv.offsetWidth
	}
	
	if(y > iDiv.offsetHeight - gDiv.offsetHeight){
		
		y = iDiv.offsetHeight - gDiv.offsetHeight
	}
	
	gDiv.style.left = x+"px";
	gDiv.style.top = y+"px";
	
	bIm.style.left = x*-2+"px";
	bIm.style.top = y*-2+"px";
}

iDiv.onmouseover = function(){
	
	gDiv.style.display = "block";
	bDiv.style.display = "block";
}

iDiv.onmouseout = function(){
	
	gDiv.style.display = "none";
	bDiv.style.display = "none";
}


/*************图片的选择****************/
var imgs = Array.from(document.getElementsByClassName("d-img"));

imgs.forEach(function(img,ind){
	
	img.onclick = function(){
		
		imInd = ind;
		tab();
	}
})


var imInd = 0;
tab();

function tab(){
	
	imgs.forEach(function(img,ind){
		
		img.style.border = "0 none";
	})
	
	imgs[imInd].style.border = "2px solid #c00";
	
	oImg.src = imgs[imInd].currentSrc;
	bIm.src = imgs[imInd].currentSrc;
}

/****************倒计时****************/

var oDiv = document.getElementById("group-over-time");
var dSpan = document.getElementById("dates");
var hSpan = document.getElementById("hours");
var mSpan = document.getElementById("minutes");
var sSpan = document.getElementById("seconds");

var timer = setInterval(function(){
	
	var endTime = 1508551712622;//结束时间
	var currentTime = new Date().getTime();//返回当前时间到1970年-1-1的毫秒数
	var ms = endTime - currentTime;
	
	if(ms > 0){
		
		var d = parseInt(ms/(1000*60*60*24));//计算天数
		ms = ms%(1000*60*60*24);
					
		var h = parseInt(ms/(1000*60*60));//小时
		ms = ms%(1000*60*60);
		
		if(h<10){
			
			h = "0"+h.toString();
		}
		
		
					
		var m = parseInt(ms/(1000*60));//分钟
		ms = ms%(1000*60);
		if(m<10){
			
			m = "0"+m.toString();
		}
					
		var s = parseInt(ms/1000);//秒
		ms = ms%1000;
		
		if(s<10){
			
			s = "0"+s.toString();
		}
		
		dSpan.innerHTML = d+"天";
		hSpan.innerHTML = h;
		mSpan.innerHTML = m;
		sSpan.innerHTML = s;
		
	}else{
		
		oDiv.innerHTML = "已结束"
		clearInterval(timer);
	}
	
},1000);


/***************城市列表选择器*******************/
$("#area-name").mouseenter(function(){
	
	$("#selecet-layer-wrap").slideDown();
	
}).mouseleave(function(){
	
	$("#selecet-layer-wrap").slideUp();
	
})

/*关闭*/
$("#close").click(function(){
	
	$("#selecet-layer-wrap").slideUp();
})

$("#area-list-ul > li").each(function(ind,li){
	
	$(li).bind("click",function(){
		
		$("#area-name").children("i")[0].innerHTML = li.innerText;
		
		$("#currentLi").children("span")[0].innerHTML = li.innerText;
		
		$("#selecet-layer-wrap").slideUp();
	})
})


/**********加入到购物车************/

var pro = {
	
	"store":"爱科生活官方旗舰店",
	"title":"华为 P10 全网通 4GB+64GB/128GB 移动联通电信4G手机 双卡双带",
	"color":"颜色：钻雕蓝行货64GB",
	"group":"套装：官方标配",
	"orPrice":3199.00,
	"price":2999.00,
	"count":1,
	"pic":"../images/proImg.jpg",
	"time":1508551712622,
};


/**********************登录检测************************/
if(getCookie("user")){
	
	var obj = getCookie("user");
	uSpan.innerHTML = "您好，"+"<a href='#'>"+obj.name+"</a>";
	aSpan.innerHTML = "<a id='log-out' class='log-out'>退出</a>"
	
	var oSpan = document.getElementById("log-out");
	oSpan.onclick = function(){
		
		//清除登录数据，刷新当前页面
		setCookie("user",null,0);
		window.location.href="index.html"
	}
	
	$("#shop-cart-num").click(function(){
		
		window.location.href="shopCart.html";
	})
	
	$("#shop-cart").click(function(){
		
		window.location.href="shopCart.html";
	})
	
	
	/**********************购物车检测**********************/
	$("#buystore").click(function(){
	
		if(getCookie("cartList")){
			
			var obj = getCookie("cartList");
			
			obj.list.push(pro);
			
			setCookie("cartList",obj,7);
			
		}else{
			
			setCookie("cartList",{"list":[pro]},7);
		}
		
		history.go(0);
		
	});
	
	if(getCookie("cartList")){
		
		var ary = Array.from(getCookie("cartList").list);
		
		$("#shop-cart-num").html("购物车"+ary.length+"件");
		
		$("#shop-cart-num2").html(ary.length);
		
	}else{
		
		$("#shop-cart-num").html("购物车0件");
		$("#shop-cart-num2").html(0);
	}
	
	
}else{
	
	$("#shop-cart-num").html("购物车0件");
	$("#shop-cart-num2").html(0);
	
	$("#shop-cart-num").click(function(){
		
		window.location.href="login.html";
	})
	
	$("#shop-cart").click(function(){
		
		window.location.href="login.html ";
	})
	
	$("#buystore").click(function(){
		
		window.location.href="login.html ";
	});
	
}






















